<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>自定义指令</title>
</head>
<body>


<div id="app">
    <p v-upper-text="message"></p>
    自动获取焦点:<input  type="text" v-focus>
</div>


<script src="node_modules/vue/dist/vue.js"></script>
<script>

    /* 1:  注册一个全局指令，注意全局指令不可以带v- */
    Vue.directive('upper-text', {
        bind(el, binding) {
            el.style.color = 'red'
        },
        inserted: function (el, binding) {
            el.innerHTML = binding.value.toUpperCase()
        },
        update(el, binding) {

            console.log("update")
        },
        componentUpdated(el, binding) {

            console.log("componentUpdated")
        },
        unbind(el, binding) {

            console.log("unbind")
        }
    });


    new Vue({
        el: '#app',
        data: {
            message: "sssss尚国庆"
        },
        directives: {
            'focus': {
                inserted(el, binding) {
                    el.focus();

                }
            }
        }
    });

</script>

</body>
</html>
